"""
作者:"陈强"
"""
# 引入模块
from ecshop.MY_ECShop.common.base import Base, create_loading_browser
import time


# 创建一个调节会员账户类
class PageVipAdjustAccount(Base):
    # 定义属性
    url = "http://localhost:8080/ecshop/admin/index.php"  # 网址
    vip_manage = ("class name", "icon-members")  # 会员管理
    vip_list = ("link text", "会员列表")  # 会员列表
    click_account = ("xpath", '//*[@id="listDiv"]/table/tbody/tr[3]/td[10]/a[4]')
    click_adjust_vip = ("xpath", '/html/body/h1/a')
    account_change = ('name', 'change_desc')
    user_money = ('name', 'user_money')
    frozen_money = ('name', 'frozen_money')
    pay_points_select = ('name', 'add_sub_pay_points')
    pay_points_input = ("name", 'pay_points')
    sure_button = ("class name", "button")
    text = ('xpath', '//*[@id="listDiv"]/table[1]/tbody/tr[2]/td[2]')
    # 定义方法
    """确定网页"""

    def page_adjust_open_web(self):
        self.base_open_web(self.url)

    """进入iframe标签"""

    def page_adjust_iframe(self,your_iframe):
        self.base_name_iframe_window(your_iframe)

    """退出iframe标签"""

    def page_adjust_quit_iframe(self):
        self.base_quit_all_iframe()

    """点击会员管理"""

    def page_adjust_click_manage(self):
        self.base_click(self.vip_manage)

    """点击会员列表"""

    def page_adjust_click_list(self):
        self.base_click(self.vip_list)

    """点击查看账目明细"""

    def page_adjust_click_account(self):
        self.base_click(self.click_account)

    """点击调节会员账户"""

    def page_adjust_click_vip(self):
        self.base_click(self.click_adjust_vip)

    """账户变动原因输入"""

    def page_adjust_input_account_change(self, your_content):
        self.base_input_massage(self.account_change, your_content)

    """可用资金输入框"""

    def page_adjust_user_money(self, your_num):
        self.base_input_massage(self.user_money, your_num)

    """冻结资金输入框"""

    def page_adjust_frozen_money(self, your_num):
        self.base_input_massage(self.frozen_money, your_num)


    """消费积分输入框"""

    def page_adjust_input_pay_points(self, your_num):
        self.base_input_massage(self.pay_points_input, your_num)

    """点击确定"""

    def page_adjust_click_sure(self):
        self.base_click(self.sure_button)

    """获取文本"""

    def page_adjust_get_text(self):
        return self.base_get_text(self.text)

    """关闭"""

    def page_adjust_quit(self):
        self.base_quit_web()


if __name__ == '__main__':
    driver = PageVipAdjustAccount(create_loading_browser())
    driver.page_adjust_open_web()
    driver.page_adjust_iframe(0)
    driver.page_adjust_click_manage()
    driver.page_adjust_click_list()
    driver.page_adjust_quit_iframe()
    # 进入2层iframe
    driver.page_adjust_iframe('main-frame')
    # 点击查看账目明细
    driver.page_adjust_click_account()
    # 点击调节会员账户
    driver.page_adjust_click_vip()
    # 输入账户变动原因
    driver.page_adjust_input_account_change('下单流程测试')
    # 可用资金输入
    driver.page_adjust_user_money('100000')
    # 冻结资金输入
    driver.page_adjust_frozen_money('500')
    # 消费积分输入
    driver.page_adjust_input_pay_points('2000')
    # 点击确定
    driver.page_adjust_click_sure()
    time.sleep(12)
    # 获取文本
    print(driver.page_adjust_get_text())
    # # 关闭
    # driver.page_adjust_quit()


